<script setup>
import { ref, onMounted, computed } from "vue";

// 支付宝用户ID和赏金二维码token - 从环境变量中读取
const alipayUserId = ref((window.ENV_CONFIG && window.ENV_CONFIG.VITE_ALIPAY_USER_ID) || "2088922557117308");
const qrToken = ref((window.ENV_CONFIG && window.ENV_CONFIG.VITE_QR_TOKEN) || "AhGZ19610515y4vfkzko7jotd85w2O");
// 跳转地址
const jumpURL = ref(
  `https://ulink.alipay.com/?scheme=alipays%3A%2F%2Fplatformapi%2Fstartapp%3FsaId%3D10000007%26clientVersion%3D3.7.0.0718%26qrcode%3Dhttps%253A%252F%252Frender.alipay.com%252Fp%252Fc%252Falipay-red-qrcode%252Fshared.html%253Fchannel%253Dsearch_pwd%2526shareId%253D${alipayUserId.value}%2526token%253D${qrToken.value}%2526campStr%253DkPPFvOxaCL3f85TiKss2wsBZgIjulHjG%2526sign%253DqsiVOoa7TuphryWxyBdONXsMTnE3jiIBvWeUs3yV1sw%253D%2526chInfo%253DDingtalk%2526c_stype%253Dsearch_pwd`
);

// 使用ref创建响应式变量
const amount = ref(0);
const displayAmount = computed(() => {
  return amount.value.toFixed(2);
});

// 随机生成金额并显示动画的方法
const startAmountAnimation = () => {
  const randomAmount = Math.random() * 10 + 3;
  const target = parseFloat(randomAmount);
  const duration = 1500; // 动画时间1.5秒
  const steps = 100;
  const increment = target / steps;
  let count = 0;

  const interval = setInterval(() => {
    amount.value += increment;
    count++;
    if (count >= steps) {
      amount.value = target;
      clearInterval(interval);
    }
  }, duration / steps);
};

// 获取设备（操作系统或者指定APP）
const getMobileOS = () => {
  const ua = navigator.userAgent || navigator.vendor || window.opera;
  // 判断是否为抖音（Douyin）
  if (/aweme|douyin/i.test(ua)) {
    return "Douyin";
  }
  // 判断是否为 Android
  if (/android/i.test(ua)) {
    return "Android";
  }
  // 判断是否为 iOS
  if (/iPad|iPhone|iPod/.test(ua) && !window.MSStream) {
    return "iOS";
  }
  // 判断是否为 PC
  if (/Windows NT|Macintosh/.test(ua)) {
    return "PC";
  }
  return "unknown";
};

// 判断是否是微信浏览器
const isWeChat = () => {
  return /MicroMessenger/i.test(navigator.userAgent);
};

// 调试模式的电脑系统检测
const isPC = () => {
  // 使用userAgent替代已弃用的platform
  const ua = navigator.userAgent.toLowerCase();

  // 检查是否为移动设备
  const isMobile = /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(ua);

  // 额外检查屏幕宽度，通常移动设备屏幕较窄
  const isSmallScreen = window.innerWidth < 768;

  // 如果是移动设备或小屏幕，则不是PC
  return !(isMobile || isSmallScreen);
};

// Android设备跳转
const jumpTo_Android = () => {
  if (isWeChat()) {
    // 如果是安卓微信内
    weui.alert('请在右上角[···]选择在浏览器打开！');
  } else {
    // 如果不是微信浏览器
    // 跳转到指定页面
    location.href = jumpURL.value;
  }
};

// iOS设备跳转
const jumpTo_iOS = () => {
  if (confirm("点击右上角[···]在浏览器打开可正常跳转！")) {
    // 跳转入口1
    location.href = jumpURL.value;
  } else {
    // 跳转入口2
    location.href = `https://ace.tb.cn/t?smburl=tbopen://m.taobao.com/tbopen/index.html?h5Url=${jumpURL.value}`;
  }
};

// 不同的设备不同的跳转情况
const jumpTo = () => {
  if (getMobileOS() == "Douyin") {
    // 在抖音打开
    location.href = jumpURL.value;
  } else if (isPC() && getMobileOS() !== "Android") {
    // 在电脑打开（调试模式）
    weui.alert("仅限手机端打开");
  } else if (getMobileOS() == "PC") {
    // 在电脑打开
    weui.alert("仅限手机端打开");
  } else if (getMobileOS() == "Android") {
    // 在Android设备打开
    jumpTo_Android();
  } else if (getMobileOS() == "iOS") {
    // 在iOS设备打开
    jumpTo_iOS();
  } else {
    // 直跳
    location.href = jumpURL.value;
  }
};

// 页面加载完成后执行
onMounted(() => {
  // 如果不是微信内也不是电脑系统，直接跳转
  if (!isWeChat() && !isPC()) {
    location.href = jumpURL.value;
  }

  // 启动金额动画
  startAmountAnimation();
});
</script>

<template>
  <div class="container">
    <div class="header">
      <div class="title">支付宝天天有红包</div>
      <div class="subtitle">到店扫 更惊喜</div>
    </div>
    <div class="notice">
      <div class="noticeIco">
        <svg
          t="1754035001272"
          class="icon"
          viewBox="0 0 1024 1024"
          version="1.1"
          xmlns="http://www.w3.org/2000/svg"
          p-id="7379"
          width="24"
          height="24"
        >
          <path
            d="M573.04 126.77a32.364 32.364 0 0 0-35.29 7L329.23 341.84H192.39c-42 0.04-76.03 34.09-76.06 76.08v192.56c0.05 41.99 34.08 76.01 76.06 76.06h136.95l208.67 203.92a32.33 32.33 0 0 0 22.63 9.23c17.88-0.02 32.36-14.52 32.37-32.4v-710.6c0.01-13.09-7.87-24.9-19.97-29.92zM696.65 318.89c-11.42-11.16-29.73-10.96-40.89 0.46-11.17 11.42-10.96 29.73 0.46 40.9a215.235 215.235 0 0 1 64.81 152.71A215.294 215.294 0 0 1 658 666.42a28.92 28.92 0 0 0-6.26 31.52 28.904 28.904 0 0 0 26.73 17.84c7.66 0 14.99-3.05 20.39-8.47 51.6-51.6 80.41-121.7 79.99-194.68a273.144 273.144 0 0 0-82.2-193.74z"
            fill="#fe1c42"
            p-id="7380"
            data-spm-anchor-id="a313x.search_index.0.i1.a4d53a81PkY4Wq"
            class=""
          ></path>
          <path
            d="M786.33 226.64c-11.47-10.92-29.58-10.58-40.64 0.75-11.06 11.33-10.95 29.45 0.25 40.65 66.91 65.29 103.76 152.74 103.76 246.17 0 93.32-36.74 180.64-103.48 245.9-8.41 8.22-11 20.71-6.56 31.6a28.919 28.919 0 0 0 26.78 18.01 28.84 28.84 0 0 0 20.22-8.24A401.449 401.449 0 0 0 907.68 514c-0.07-108.24-43.82-211.85-121.35-287.36z"
            fill="#fe1c42"
            p-id="7381"
            data-spm-anchor-id="a313x.search_index.0.i3.a4d53a81PkY4Wq"
            class=""
          ></path>
        </svg>
      </div>
      <div class="noticeTitle">7月30日起，领取你的惊喜大红包~</div>
    </div>
    <div class="imhHB" @click="jumpTo">
      <div class="tip">
        <div class="tipTitle">
          <div class="tipico">
            <svg
              t="1754037419982"
              class="icon"
              viewBox="0 0 1024 1024"
              version="1.1"
              xmlns="http://www.w3.org/2000/svg"
              p-id="4491"
              width="22"
              height="22"
            >
              <path
                d="M902.095 652.871l-250.96-84.392s19.287-28.87 39.874-85.472c20.59-56.606 23.539-87.689 23.539-87.689l-162.454-1.339v-55.487l196.739-1.387v-39.227H552.055v-89.29h-96.358v89.294H272.133v39.227l183.564-1.304v59.513h-147.24v31.079h303.064s-3.337 25.223-14.955 56.606c-11.615 31.38-23.58 58.862-23.58 58.862s-142.3-49.804-217.285-49.804c-74.985 0-166.182 30.123-175.024 117.55-8.8 87.383 42.481 134.716 114.728 152.139 72.256 17.513 138.962-0.173 197.04-28.607 58.087-28.391 115.081-92.933 115.081-92.933l292.486 142.041c-11.932 69.3-72.067 119.914-142.387 119.844H266.37c-79.714 0.078-144.392-64.483-144.466-144.194V266.374c-0.074-79.72 64.493-144.399 144.205-144.47h491.519c79.714-0.073 144.396 64.49 144.466 144.203v386.764z m-365.76-48.895s-91.302 115.262-198.879 115.262c-107.623 0-130.218-54.767-130.218-94.155 0-39.34 22.373-82.144 113.943-88.333 91.519-6.18 215.2 67.226 215.2 67.226h-0.047z"
                fill="#1D7BFF"
                p-id="4492"
                data-spm-anchor-id="a313x.search_index.0.i0.339d3a81O25vVQ"
                class=""
              ></path>
            </svg>
          </div>
          <div class="tipText">到店立减红包</div>
        </div>
      </div>
      <div class="moneyKuang">
        <div class="money">
          <div class="moneynum">{{ displayAmount }}</div>
          <div class="units">元</div>
        </div>
        <div class="propaganda">连续3天，每天减1笔</div>
      </div>
      <img
        class="img"
        src=""
        alt=""
      />
      <div class="imhHBTitle">立即领取</div>
    </div>
    <div class="zfhl" @click="jumpTo">
      <img class="img" src="./assets/1754020265330.webp" alt="" />
    </div>

    <div class="zfbkey">本活动由支付宝官方赞助</div>
  </div>
</template>

<style scoped>
@font-face {
  font-family: "DingTalk-JinBuTi";
  src: url("./assets/font/DingTalk-JinBuTi.woff2") format("woff2"),
    url("./assets/font/DingTalk-JinBuTi.woff") format("woff");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

.container {
  background-color: #fff;
  background: linear-gradient(179deg, #1677ff 0% 0%, #ffffff 55%);
  min-height: 100vh;
  width: 100%;
  padding-top: 50px;
  color: white;
  font-family: "DingTalk-JinBuTi", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell,
    "Open Sans", "Helvetica Neue", sans-serif;
  box-sizing: border-box;
  overflow-x: hidden;
  overflow-y: scroll;
  user-select: none;
}
.container {
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* Internet Explorer 10+ */
}

/* WebKit浏览器 */
.container ::-webkit-scrollbar {
  display: none;
}
.header {
  text-align: center;
  margin-bottom: 20px;
}

.title {
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 10px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  font-family: "DingTalk-JinBuTi", sans-serif;
}

.subtitle {
  width: 100%;
  font-size: 35px;
  font-weight: bold;
  line-height: 24px;
  color: #fff;
  font-family: "DingTalk-JinBuTi", serif;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.notice {
  width: 85%;
  height: 30px;
  margin: 16px auto;
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.83);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 30px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: #3b3b3e;
  box-sizing: border-box;
  padding: 0 6px;
}

.noticeIco {
  width: 24px;
  height: 24px;
}

.noticeTitle {
  font-size: 14px;
  padding: 0 6px;
}

.imhHB {
  width: 100%;
  height: 326px;
  position: relative;
  overflow: hidden;
}

.tip {
  width: 100%;
  height: 30px;
  line-height: 30px;
  overflow: hidden;
  position: absolute;
  top: 10px;
  left: 0;
}

.tipTitle {
  width: 40%;
  height: 30px;
  background-color: #ffe4cf;
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 16px;
  text-align: center;
  color: #e77b50;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  justify-items: center;
}

.tipico {
  width: 22px;
  height: 22px;
}

.moneyKuang {
  width: fit-content;
  height: 100px;
  position: absolute;
  top: 30px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  box-sizing: border-box;
}
.money {
  width: fit-content;
  font-size: 56px;
  font-weight: bold;
  color: #ff3646;
  padding: 20px 0 16px 0;
  box-sizing: border-box;
  display: flex;
  align-items: end;
}
.moneynum {
  max-width: 160px;
  min-width: 140px;
  width: fit-content;
  text-align: center;
}
.units {
  font-size: 26px;
  height: 37px;
}
.propaganda {
  font-size: 16px;
  color: #e4824f;
  text-align: center;
}
.imhHBTitle {
  position: absolute;
  bottom: 57px;
  left: 0;
  width: 100%;
  height: 30px;
  line-height: 30px;
  z-index: 3;
  color: #ff3646;
  font-weight: bold;
  text-align: center;
  font-size: 23px;
  display: inline-block;
  /* 必须设置，transform 才能生效 */
  animation: textScale 1.5s infinite ease-in-out;
}

@keyframes textScale {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.1);
    /* 放大到 1.3 倍 */
  }

  100% {
    transform: scale(1);
  }
}

.img {
  width: 100%;
  height: 100%;
}

.zfhl {
  width: 90%;
  height: fit-content;
  margin: 16px auto;
  overflow: hidden;
  border-radius: 10px;
}

.zfbkey {
  width: 100%;
  height: 35px;
  text-align: center;
  border-radius: 2px;
  color: #b7b7b7;
  margin-top: 55px;
  font-size: 14px;
}
</style>
